package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AuditRoute;
import com.ruoyi.system.service.IAuditRouteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 审核路径实例（节点级）Controller
 * 
 * @author ruoyi
 * @date 2025-11-07
 */
@RestController
@RequestMapping("/system/route")
public class AuditRouteController extends BaseController
{
    @Autowired
    private IAuditRouteService auditRouteService;

    /**
     * 查询审核路径实例（节点级）列表
     */
    @PreAuthorize("@ss.hasPermi('system:route:list')")
    @GetMapping("/list")
    public TableDataInfo list(AuditRoute auditRoute)
    {
        startPage();
        List<AuditRoute> list = auditRouteService.selectAuditRouteList(auditRoute);
        return getDataTable(list);
    }

    /**
     * 查询可驳回节点
     */
    @GetMapping("/rollbackOptions")
    public AjaxResult rollbackOptions(Long businessId, String auditBusinessType, Long currentRouteId)
    {
        return success(auditRouteService.selectRollbackOptions(businessId, auditBusinessType, currentRouteId));
    }

    /**
     * 导出审核路径实例（节点级）列表
     */
    @PreAuthorize("@ss.hasPermi('system:route:export')")
    @Log(title = "审核路径实例（节点级）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AuditRoute auditRoute)
    {
        List<AuditRoute> list = auditRouteService.selectAuditRouteList(auditRoute);
        ExcelUtil<AuditRoute> util = new ExcelUtil<AuditRoute>(AuditRoute.class);
        util.exportExcel(response, list, "审核路径实例（节点级）数据");
    }

    /**
     * 获取审核路径实例（节点级）详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:route:query')")
    @GetMapping(value = "/{auditRouteId}")
    public AjaxResult getInfo(@PathVariable("auditRouteId") Long auditRouteId)
    {
        return success(auditRouteService.selectAuditRouteByAuditRouteId(auditRouteId));
    }

    /**
     * 新增审核路径实例（节点级）
     */
    @PreAuthorize("@ss.hasPermi('system:route:add')")
    @Log(title = "审核路径实例（节点级）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuditRoute auditRoute)
    {
        return toAjax(auditRouteService.insertAuditRoute(auditRoute));
    }

    /**
     * 修改审核路径实例（节点级）
     */
    @PreAuthorize("@ss.hasPermi('system:route:edit')")
    @Log(title = "审核路径实例（节点级）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuditRoute auditRoute)
    {
        return toAjax(auditRouteService.updateAuditRoute(auditRoute));
    }

    /**
     * 删除审核路径实例（节点级）
     */
    @PreAuthorize("@ss.hasPermi('system:route:remove')")
    @Log(title = "审核路径实例（节点级）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{auditRouteIds}")
    public AjaxResult remove(@PathVariable String[] auditRouteIds)
    {
        return toAjax(auditRouteService.deleteAuditRouteByAuditRouteIds(auditRouteIds));
    }
}
